package top.hjcwzx.domain.test.service.tree.node;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.hjcwzx.domain.test.model.tree.TreeReq;
import top.hjcwzx.domain.test.model.tree.TreeRes;
import top.hjcwzx.domain.test.service.tree.AbstractTestSupport;
import top.hjcwzx.domain.test.service.tree.factory.DefaultTreeTestFactory;
import top.hjcwzx.types.design.framework.tree.StrategyHandler;

/**
 * {@code @author} hujincheng <br/>
 * {@code @description} 开关节点 <br/>
 * {@code @create} 2025-04-01 10:48 <br/>
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class SwitchNode extends AbstractTestSupport<TreeReq, DefaultTreeTestFactory.DynamicContext, TreeRes> {

    private final TestNode testNode;
    private final ErrorNode errorNode;

    @Override
    public TreeRes apply(TreeReq requestParameter, DefaultTreeTestFactory.DynamicContext dynamicContext) throws Exception {
        log.info("抽象规则决策树-开关节点路由节点");
        return router(requestParameter, dynamicContext);
    }

    @Override
    public StrategyHandler<TreeReq, DefaultTreeTestFactory.DynamicContext, TreeRes> get(TreeReq requestParameter, DefaultTreeTestFactory.DynamicContext dynamicContext) throws Exception {
        Boolean switchControl = requestParameter.getSwitchControl();
        if(switchControl){
            log.info("抽象规则决策树-开关节点流转-下一节点-错误节点:{}", errorNode);
            return errorNode;
        }
        log.info("抽象规则决策树-开关节点流转-下一节点-测试业务节点:{}", testNode);
        return testNode;
    }
}
